using Microsoft.Win32;
using NoteManger.Properties;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace NoteManger
{
	public class FrmUserLogin : TemplateForm
	{
		private IContainer components = null;
		private TextBox tboxUserID;
		private Button btnCancel;
		private GroupBox groupBox;
		private Button btnLogin;
		private PictureBox pboxPassword;
		private PictureBox pboxUserID;
		private TextBox tboxUserPwd;
		private Label label2;
		private Label label1;
		private GroupBox gboxsplit;
		private PictureBox pboxUserName;
		private Label label3;
		private TextBox tboxUserName;
		private Button btnHelp;
		private NoteRemote _NoteRemoteObject = null;
		private TLoginInfo _LoginInfo = new TLoginInfo();
		private bool _AutoLogin = false;
		public NoteRemote NoteRemoteObject
		{
			set
			{
				this._NoteRemoteObject = value;
			}
		}
		public TLoginInfo LoginInfo
		{
			get
			{
				return this._LoginInfo;
			}
		}
		public bool AutoLogin
		{
			get
			{
				return this._AutoLogin;
			}
			set
			{
				this._AutoLogin = value;
			}
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.tboxUserID = new TextBox();
			this.btnCancel = new Button();
			this.groupBox = new GroupBox();
			this.pboxUserName = new PictureBox();
			this.label3 = new Label();
			this.tboxUserName = new TextBox();
			this.gboxsplit = new GroupBox();
			this.btnLogin = new Button();
			this.pboxPassword = new PictureBox();
			this.pboxUserID = new PictureBox();
			this.tboxUserPwd = new TextBox();
			this.label2 = new Label();
			this.label1 = new Label();
			this.btnHelp = new Button();
			this.groupBox.SuspendLayout();
			((ISupportInitialize)this.pboxUserName).BeginInit();
			((ISupportInitialize)this.pboxPassword).BeginInit();
			((ISupportInitialize)this.pboxUserID).BeginInit();
			base.SuspendLayout();
			this.tboxUserID.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.tboxUserID.Location = new System.Drawing.Point(168, 39);
			this.tboxUserID.Name = "tboxUserID";
			this.tboxUserID.Size = new System.Drawing.Size(215, 23);
			this.tboxUserID.TabIndex = 0;
			this.tboxUserID.KeyPress += new KeyPressEventHandler(this.tboxUserID_KeyPress);
			this.btnCancel.BackColor = System.Drawing.Color.FromArgb(192, 192, 255);
			this.btnCancel.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.btnCancel.ForeColor = System.Drawing.Color.FromArgb(51, 79, 103);
			this.btnCancel.Location = new System.Drawing.Point(304, 216);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(79, 26);
			this.btnCancel.TabIndex = 3;
			this.btnCancel.Text = "取消";
			this.btnCancel.UseVisualStyleBackColor = false;
			this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
			this.groupBox.BackColor = System.Drawing.Color.FromArgb(51, 79, 103);
			this.groupBox.Controls.Add(this.btnHelp);
			this.groupBox.Controls.Add(this.pboxUserName);
			this.groupBox.Controls.Add(this.label3);
			this.groupBox.Controls.Add(this.tboxUserName);
			this.groupBox.Controls.Add(this.gboxsplit);
			this.groupBox.Controls.Add(this.btnLogin);
			this.groupBox.Controls.Add(this.pboxPassword);
			this.groupBox.Controls.Add(this.pboxUserID);
			this.groupBox.Controls.Add(this.tboxUserPwd);
			this.groupBox.Controls.Add(this.label2);
			this.groupBox.Controls.Add(this.label1);
			this.groupBox.Controls.Add(this.tboxUserID);
			this.groupBox.Controls.Add(this.btnCancel);
			this.groupBox.Font = new System.Drawing.Font("宋体", 11f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.groupBox.ForeColor = System.Drawing.Color.White;
			this.groupBox.Location = new System.Drawing.Point(14, 21);
			this.groupBox.Name = "groupBox";
			this.groupBox.Size = new System.Drawing.Size(400, 255);
			this.groupBox.TabIndex = 9;
			this.groupBox.TabStop = false;
			this.groupBox.Text = "用户登录";
			this.pboxUserName.InitialImage = null;
			this.pboxUserName.Location = new System.Drawing.Point(15, 85);
			this.pboxUserName.Name = "pboxUserName";
			this.pboxUserName.Size = new System.Drawing.Size(48, 48);
			this.pboxUserName.SizeMode = PictureBoxSizeMode.StretchImage;
			this.pboxUserName.TabIndex = 19;
			this.pboxUserName.TabStop = false;
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.label3.ForeColor = System.Drawing.Color.Transparent;
			this.label3.Location = new System.Drawing.Point(69, 101);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(84, 14);
			this.label3.TabIndex = 18;
			this.label3.Text = "用户姓名(&N)";
			this.tboxUserName.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.tboxUserName.Location = new System.Drawing.Point(168, 98);
			this.tboxUserName.Name = "tboxUserName";
			this.tboxUserName.Size = new System.Drawing.Size(215, 23);
			this.tboxUserName.TabIndex = 17;
			this.gboxsplit.Location = new System.Drawing.Point(5, 193);
			this.gboxsplit.Name = "gboxsplit";
			this.gboxsplit.Size = new System.Drawing.Size(391, 9);
			this.gboxsplit.TabIndex = 16;
			this.gboxsplit.TabStop = false;
			this.btnLogin.BackColor = System.Drawing.Color.FromArgb(192, 192, 255);
			this.btnLogin.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.btnLogin.ForeColor = System.Drawing.Color.FromArgb(51, 79, 103);
			this.btnLogin.Location = new System.Drawing.Point(200, 216);
			this.btnLogin.Name = "btnLogin";
			this.btnLogin.Size = new System.Drawing.Size(86, 26);
			this.btnLogin.TabIndex = 2;
			this.btnLogin.Text = "登录(&L)";
			this.btnLogin.UseVisualStyleBackColor = false;
			this.btnLogin.Click += new EventHandler(this.btnLogin_Click);
			this.pboxPassword.Location = new System.Drawing.Point(15, 142);
			this.pboxPassword.Name = "pboxPassword";
			this.pboxPassword.Size = new System.Drawing.Size(48, 48);
			this.pboxPassword.SizeMode = PictureBoxSizeMode.StretchImage;
			this.pboxPassword.TabIndex = 13;
			this.pboxPassword.TabStop = false;
			this.pboxUserID.InitialImage = null;
			this.pboxUserID.Location = new System.Drawing.Point(15, 26);
			this.pboxUserID.Name = "pboxUserID";
			this.pboxUserID.Size = new System.Drawing.Size(48, 48);
			this.pboxUserID.SizeMode = PictureBoxSizeMode.StretchImage;
			this.pboxUserID.TabIndex = 12;
			this.pboxUserID.TabStop = false;
			this.tboxUserPwd.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.tboxUserPwd.Location = new System.Drawing.Point(168, 153);
			this.tboxUserPwd.Name = "tboxUserPwd";
			this.tboxUserPwd.PasswordChar = '☻';
			this.tboxUserPwd.Size = new System.Drawing.Size(215, 23);
			this.tboxUserPwd.TabIndex = 1;
			this.tboxUserPwd.KeyPress += new KeyPressEventHandler(this.tboxUserPwd_KeyPress);
			this.tboxUserPwd.Enter += new EventHandler(this.tboxUserPwd_Enter);
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.label2.ForeColor = System.Drawing.Color.Transparent;
			this.label2.Location = new System.Drawing.Point(70, 158);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(84, 14);
			this.label2.TabIndex = 10;
			this.label2.Text = "密    码(&P)";
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
			this.label1.ForeColor = System.Drawing.Color.Transparent;
			this.label1.Location = new System.Drawing.Point(69, 42);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(84, 14);
			this.label1.TabIndex = 9;
			this.label1.Text = "用户编号(&U)";

			this.btnHelp.Location = new System.Drawing.Point(15, 216);
			this.btnHelp.Name = "btnHelp";
			this.btnHelp.Size = new System.Drawing.Size(24, 24);
			this.btnHelp.TabIndex = 31;
			this.btnHelp.UseVisualStyleBackColor = true;
			this.btnHelp.Click += new EventHandler(this.btnHelp_Click);
			base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);

			this.BackColor = System.Drawing.Color.FromArgb(51, 79, 103);
			base.ClientSize = new System.Drawing.Size(429, 288);
			base.Controls.Add(this.groupBox);

			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "FrmUserLogin";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "用户登录";
			base.TransparencyKey = System.Drawing.Color.Red;
			base.Shown += new EventHandler(this.FrmUserLogin_Shown);
			this.groupBox.ResumeLayout(false);
			this.groupBox.PerformLayout();
			((ISupportInitialize)this.pboxUserName).EndInit();
			((ISupportInitialize)this.pboxPassword).EndInit();
			((ISupportInitialize)this.pboxUserID).EndInit();
			base.ResumeLayout(false);
		}
		public FrmUserLogin()
		{
			this.InitializeComponent();
			try
			{
				System.Drawing.Image image = System.Drawing.Image.FromFile(NoteRemote.GetNoteClientStartPath() + "\\png\\Dep.png");
				this.pboxUserID.Image = image;
				image = System.Drawing.Image.FromFile(NoteRemote.GetNoteClientStartPath() + "\\png\\Login.png");
				this.pboxUserName.Image = image;
				image = System.Drawing.Image.FromFile(NoteRemote.GetNoteClientStartPath() + "\\png\\Key.png");
				this.pboxPassword.Image = image;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}
		private void btnLogin_Click(object sender, EventArgs e)
		{
			try
			{
				if (!this._NoteRemoteObject.ConnectionTest())
				{
					MessageBox.Show("远程连接已断开，请重新连接后再试！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					return;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message + "远程连接已断开，请重新连接后再试！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			this.tboxUserID.Focus();
			string text = "";
			object[] array = new object[0];
			try
			{
				this._NoteRemoteObject.UserLogin(this.tboxUserID.Text.Trim(), this.tboxUserPwd.Text.Trim(), ref array, ref text);
				this._LoginInfo.LoginSuccess = (bool)array[0];
				this._LoginInfo.LoginID = (string)array[1];
				this._LoginInfo.LoginName = (string)array[2];
				this._LoginInfo.DepID = (string)array[3];
				this._LoginInfo.GroupID = (string)array[4];
				this._LoginInfo.PurviewID = (string)array[5];
			}
			catch (Exception ex)
			{
				this._LoginInfo.LoginSuccess = false;
				this._LoginInfo.LoginID = "";
				this._LoginInfo.LoginName = "";
				this._LoginInfo.DepID = "";
				this._LoginInfo.GroupID = "";
				this._LoginInfo.PurviewID = "";
				MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
			if (!this._LoginInfo.LoginSuccess)
			{
				MessageBox.Show(text, "登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
			else
			{
				base.DialogResult = DialogResult.OK;
			}
		}
		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}
		private void tboxUserID_KeyPress(object sender, KeyPressEventArgs e)
		{
			string text = "";
			if (e.KeyChar == '\r')
			{
				try
				{
					if (!this._NoteRemoteObject.ConnectionTest())
					{
						MessageBox.Show("远程连接已断开，请重新连接后再试！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						return;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message + "远程连接已断开，请重新连接后再试！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					return;
				}
				string text2 = "";
				if (!this._NoteRemoteObject.GetUserName(this.tboxUserID.Text.Trim(), ref text2, ref text))
				{
					this.tboxUserID.Focus();
					MessageBox.Show(text, "登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					this.tboxUserName.Text = text2;
					e.Handled = true;
					this.tboxUserPwd.Focus();
				}
			}
		}
		private void tboxUserPwd_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				e.Handled = true;
				this.btnLogin_Click(null, null);
			}
		}
		private void tboxUserPwd_Enter(object sender, EventArgs e)
		{
			string text = "";
			if (this.tboxUserID.Text.Trim() != "")
			{
				try
				{
					if (!this._NoteRemoteObject.ConnectionTest())
					{
						MessageBox.Show("远程连接已断开，请重新连接后再试！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						return;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message + "远程连接已断开，请重新连接后再试！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					return;
				}
				string text2 = "";
				if (!this._NoteRemoteObject.GetUserName(this.tboxUserID.Text.Trim(), ref text2, ref text))
				{
					this.tboxUserID.Focus();
					MessageBox.Show(text, "登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					this.tboxUserName.Text = text2;
				}
			}
		}
		private void ReadClientConfig()
		{
			try
			{
				RegistryKey localMachine = Registry.LocalMachine;
				RegistryKey registryKey = localMachine.OpenSubKey("Software\\KSExpert", true);
				object value = registryKey.GetValue("AutoLoginID");
				if (value == null)
				{
					this.tboxUserID.Text = "";
				}
				else
				{
					this.tboxUserID.Text = value.ToString();
					this.tboxUserID.SelectionStart = this.tboxUserID.Text.Length;
				}
				for (int i = 0; i < 20000; i++)
				{
					Application.DoEvents();
				}
				value = registryKey.GetValue("AutoLoginPwd");
				if (value == null)
				{
					this.tboxUserPwd.Text = "";
				}
				else
				{
					this.tboxUserPwd.Text = value.ToString();
					this.tboxUserPwd.SelectionStart = this.tboxUserPwd.Text.Length;
				}
				KeyPressEventArgs e = new KeyPressEventArgs('\r');
				this.tboxUserID_KeyPress(null, e);
				for (int i = 0; i < 20000; i++)
				{
					Application.DoEvents();
				}
				this.tboxUserPwd_KeyPress(null, e);
			}
			catch
			{
			}
		}
		private void FrmUserLogin_Shown(object sender, EventArgs e)
		{
			if (this._AutoLogin)
			{
				this.ReadClientConfig();
			}
		}
		private void btnHelp_Click(object sender, EventArgs e)
		{
			Help.ShowHelp(new Control(), NoteRemote.GetNoteClientStartPath() + "\\日志管理系统帮助文件.chm", "登录.htm");
		}
	}
}
